﻿(function () {
    angular.module('KtotApp').controller('ProjectController', ['TaskService', '$routeParams', '$location', function (taskService, $routeParams, $location) {
        Ktot.BaseController(this);
        var self = this;
        self.model = {};

        self.init = function () {

        };

        self.onSave = function () {
            taskService.saveProject(self.model).then(function () {
                $location.path('/work');
            }).fail(self.defaultErrorHandler);
        };
        
        self.onValidate = function () {
            if (Utils.isEmpty(self.model.title)) {
                self.addRequiredError('title', 'Title');
            }

            if (Utils.isEmpty(self.model.name)) {
                self.addRequiredError('name', 'Title');
            }

            if (Utils.isEmpty(self.model.url)) {
                self.addRequiredError("url", "Url");
            }
        };
      
        self.edit = function () {            
            taskService.getProject($routeParams.id).then(function(project) {
                self.model = project;
            });            
        };
    }]);
})();